﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Easy.Operation;

namespace Easy.Web.Service.Privilege
{
    /// <summary>
    /// IsHaveRight 的摘要说明
    /// </summary>
    public class IsHaveRight : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            ResultClass rc = new ResultClass();


            context.Response.ContentType = "text/plain";
            string RecordId = context.Request["RecordId"];

            string UserID = context.Request["UserID"];

            string Action = context.Request["Action"];

            string EntityName = context.Request["EntityName"];

            if (RecordId == "" || RecordId == null || RecordId.Length!=36)
            {
                rc.Result = 1;
                rc.Remark = "请提供记录ID";
            }
            else if (UserID == "" || UserID == null || UserID.Length != 36)
            {
                rc.Result = 1;
                rc.Remark = "请提供用户ID";
            }
            else if (Action == "" || Action == null )
            {
                rc.Result = 1;
                rc.Remark = "请提供操作名称";
            }
            else if (Action.ToUpper() != "READ" && Action.ToUpper() != "WRITE" && Action.ToUpper() != "CREATE" && Action.ToUpper() != "DELETE" && Action.ToUpper() != "ASSIGN")
            {
                rc.Result = 1;
                rc.Remark = "请提供正确的操作名称";
                
            }
            else if (EntityName == "" || EntityName == null)
            {
                rc.Result = 1;
                rc.Remark = "请提供记录实体名";
            }
            else
            {
                string ishaveright = UserPrivilege_Functions.IsHaveRight(RecordId, UserID, Action, EntityName);
                rc.Result = 0;
                rc.Remark = ishaveright;
            }

                


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}